using SmartBoard.Book.Model;

namespace SmartBoard.Book.Commands
{
    public class SaveBookAction: BookUIActionBase
    {
        public SaveBookAction(BookManager bookManager, IBookUIManager bookUIManager) : base(bookManager, bookUIManager)
        { }

        #region ICommand Members

        public override bool CanExecute(object parameter)
        {
            return _bookManager.Book != null;
        }

        public override void Execute(object parameter)
        {
            if (string.IsNullOrEmpty(_bookManager.Book.Location))
            {
                var dialog = _bookUIManager.SaveBookDialog;
                if(dialog.PresentUI()==true)
                {
                    _bookManager.Book.Location = dialog.Location;
                }
            }
            _bookManager.Book.Save(_bookManager.Book.Location);
        }
        #endregion
    }
}